﻿
Ext.namespace('FantastPlatform', 'FantastPlatform.UI');
var stationStore = new Ext.data.Store({
    proxy: new Ext.data.HttpProxy({
        url: '../Service/PatrolTaskViewService.aspx?Action=GetOrganization'
    }),
    reader: new Ext.data.JsonReader({
        root: 'topics',
        totalProperty: 'totalCount',
        id: 'Id',
        fields: ['Name', 'Id', 'Code']
    }),
    remoteStore: true

});
stationStore.load();
FantastPlatform.UI.PatrolTaskPointEditGrid = function (config) {
    Ext.apply(this, config);

    var fileStore = new Ext.data.Store({
        proxy: new Ext.data.HttpProxy({
            url: '../Service/PatrolTaskViewService.aspx?Action=LoadPoints'
        }),
        reader: new Ext.data.JsonReader({
            root: 'topics',
            totalProperty: 'totalCount',
            id: 'Id',
            fields: ['Id', 'Name', 'SelfOrgPersonNum', 'SelfOrgCar', 'OtherOrgName', 'OtherOrgPersonNum']
        }),
        remoteStore: true
    });


    this.store = fileStore;
    var paperBar = new FantastPlatform.Common.PapeToolBar({
        store: fileStore,
        defaultNum: 8
    });
    this.paperBar = paperBar;
    this.bbar = paperBar;
    this.pageNumber = paperBar.pageSize;

    var nm = new Ext.grid.RowNumberer();
    var sm = new Ext.grid.CheckboxSelectionModel();

    this.columns = [nm, sm, {
        header: 'Id',
        dataIndex: 'Id',
        hidden: true
    }, {
        header: '点位名称',
        dataIndex: 'Name',
        width: 120,
        editor: new Ext.grid.GridEditor(new Ext.form.TextField({
            allowBlank: false,
            emptyText: '点位名称不能为空'
        })),
        sortable: true

    }, {
        header: '执行单位人数',
        width: 80,
        dataIndex: 'SelfOrgPersonNum',
        sortable: true,
        editor: new Ext.grid.GridEditor(new Ext.form.TextField({
            allowBlank: false,
            emptyText: '执行单位人数不能为空'
        }))
    }, {
        header: '执行单位车辆数',
        width: 120,
        dataIndex: 'SelfOrgCar',
        sortable: true,
        editor: new Ext.grid.GridEditor(new Ext.form.TextField({
            allowBlank: true
        }))
    }, {
        header: '支援单位',
        width: 100,
        dataIndex: 'OtherOrgName',
        sortable: true,
        editor: new Ext.grid.GridEditor(new Ext.form.TextField({
            allowBlank: true
        }))
    }, {
        header: '支援单位人数',
        width: 80,
        dataIndex: 'OtherOrgPersonNum',
        sortable: true,
        editor: new Ext.grid.GridEditor(new Ext.form.TextField({
            allowBlank: true
        }))
    }
    ];
    FantastPlatform.UI.PatrolTaskPointEditGrid.superclass.constructor.call(this, {
        loadMask: { msg: '正在加载数据...' },
        sm: sm
    });
};
Ext.extend(FantastPlatform.UI.PatrolTaskPointEditGrid, Ext.grid.EditorGridPanel, {
    onRender: function (ct, position) {
        FantastPlatform.UI.PatrolTaskPointEditGrid.superclass.onRender.call(this, ct, position);
    },
    onViewDetailsClick: function () {
        var node = checkGridSelected(this);
        if (node) {
            if (node.length > 1) {
                showErrorMessage("操作失败", "只能选择一条数据进行操作", "");
            } else {
                var fId = node[0].get('Id');
                if (fId != 0) {
                    var id = GUID();
                    detailWind = openWind('../PoliceManToScheduleGrid.aspx?id=' + fId, id, '查看该班次的警员或添加备注', 550, 350, 'edit');
                }
                else {
                    showErrorMessage("操作失败", "该记录还未保存", "");
                }
            }
        }
    },
    onUpdataClick: function (data) {
         var gridStore = this.store;
        //        this.store.removeAll();
        //        this.store.proxy.conn = { method: 'post', url: this.url };
        //        this.store.load({ params: { start: 0, limit: this.paperBar.getPageNumber(), dir: '', sort: '' },
        //            callback: function () {
        //                if (data != null) {
        var pointData = new Ext.util.JSON.decode(data.Points);
        if (pointData != null) {
            for (var i = 0; i < pointData.length; i++) {
                var MyRecord = new Ext.data.Record.create([
                         { name: 'Id', type: 'int' },
                         { name: 'Name', type: 'string' },
                         { name: 'SelfOrgPersonNum', type: 'int' },
                         { name: 'SelfOrgCar', type: 'int' },
                         { name: 'OtherOrgName', type: 'string' },
                         { name: 'OtherOrgPersonNum', type: 'int' }
                        ]);
                var p = new MyRecord({
                    Id: pointData[i].Id,
                    Name: pointData[i].Name,
                    SelfOrgPersonNum: pointData[i].SelfOrgPersonNum,
                    SelfOrgCar: pointData[i].SelfOrgCar,
                    OtherOrgName: pointData[i].OtherOrgName,
                    OtherOrgPersonNum: pointData[i].OtherOrgPersonNum
                })
                var count = gridStore.getCount();
                gridStore.insert(count, p);
            }
        }
        //    }
        //    }
        //});
    }
});